#include "Logger.h"

//1. Checks if the toggletask directory exists in the home directory.
//2. Creates the directory if it does not exist.
//3. Opens the directory if it exists.
//4. Creates the .txt file and initialises the session.

//Notes:
//1. Utilizes the QDir, found in the Qt core library. This dependency must
//be included in the release version for it to work.
void Logger::setFileName(string fileName) {
    QDir Dir(TOGGLETASK_DIR);
    bool isDir = true;

    if (!Dir.exists()) {
        Dir.mkdir(TOGGLETASK_DIR);
        isDir = Dir.setCurrent(TOGGLETASK_DIR);
    }
    else {
        isDir = Dir.setCurrent(TOGGLETASK_DIR);
    }
	
	if (!logger.is_open()) {
		logger.open(fileName);
	}

	logInfo(INITIALIZATION_MESSAGE);
}

//Creates a QDateTime class to initializes file log information
//and logs the message.
void Logger::logInfo(string message) {
	QDateTime dateTimeInfo = QDateTime::currentDateTime();
	QString formatString = "ddd MMMM d yy hh:mm:ss.zzz";

	logger << dateTimeInfo.toString(formatString).toStdString() << SEPARATOR;
	logger << message << endl;
}
